﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{
    [Table(Name = "dbo.XS")]
    public partial class XS : Entity
    {

        private string _xsId;

        private decimal _bjNum;

        private string _xsName;

        private bool _xsSex;

        private string _xsIdCard;

        private EntitySet<CJ> _CJ;

        private EntityRef<BJ> _BJ;

        public XS()
        {
            this._CJ = new EntitySet<CJ>(new Action<CJ>(this.attach_CJ), new Action<CJ>(this.detach_CJ));
            this._BJ = default(EntityRef<BJ>);
        }

        [Column(Storage = "_xsId", DbType = "VarChar(20) NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        public string XSId
        {
            get
            {
                return this._xsId;
            }
            set
            {
                if ((this._xsId != value))
                {
                    this.SendPropertyChanging("XSId");
                    this._xsId = value;
                    this.SendPropertyChanged("XSId",value);
                }
            }
        }

        [Column(Storage = "_bjNum", DbType = "Decimal(18,0)")]
        public decimal BJNum
        {
            get
            {
                return this._bjNum;
            }
            set
            {
                if ((this._bjNum != value))
                {
                    if (this._BJ.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("BJNum");
                    this._bjNum = value;
                    this.SendPropertyChanged("BJNum",value);
                }
            }
        }

        [Column(Storage = "_xsName", DbType = "VarChar(20) NOT NULL", CanBeNull = false)]
        public string XSName
        {
            get
            {
                return this._xsName;
            }
            set
            {
                if ((this._xsName != value))
                {
                    this.SendPropertyChanging("XSName");
                    this._xsName = value;
                    this.SendPropertyChanged("XSName",value);
                }
            }
        }

        [Column(Storage = "_xsSex", DbType = "Bit")]
        public bool XSSex
        {
            get
            {
                return this._xsSex;
            }
            set
            {
                if ((this._xsSex != value))
                {
                    this.SendPropertyChanging("XSSex");
                    this._xsSex = value;
                    this.SendPropertyChanged("XSSex",value);
                }
            }
        }

        [Column(Storage = "_xsIdCard", DbType = "VarChar(18) NOT NULL", CanBeNull = false)]
        public string XSIdcard
        {
            get
            {
                return this._xsIdCard;
            }
            set
            {
                if ((this._xsIdCard != value))
                {
                    this.SendPropertyChanging("XSIdcard");
                    this._xsIdCard = value;
                    this.SendPropertyChanged("XSIdcard",value);
                }
            }
        }

        [Association(Name = "XS_CJ", Storage = "_CJ", ThisKey = "XSId", OtherKey = "XSId")]
        public EntitySet<CJ> CJ
        {
            get
            {
                return this._CJ;
            }
            set
            {
                this._CJ.Assign(value);
            }
        }

        [Association(Name = "BJ_XS", Storage = "_BJ", ThisKey = "BJNum", OtherKey = "BJNum", IsForeignKey = true)]
        public BJ BJ
        {
            get
            {
                return this._BJ.Entity;
            }
            set
            {
                BJ previousValue = this._BJ.Entity;
                if (((previousValue != value)
                            || (this._BJ.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("BJ");
                    if ((previousValue != null))
                    {
                        this._BJ.Entity = null;
                        previousValue.XS.Remove(this);
                    }
                    this._BJ.Entity = value;
                    if ((value != null))
                    {
                        value.XS.Add(this);
                        this._bjNum = value.BJNum;
                    }
                    else
                    {
                        this._bjNum = default(decimal);
                    }
                    this.SendPropertyChanged("BJ",value);
                }
            }
        }

        private void attach_CJ(CJ entity)
        {
            entity.XS = this;
        }

        private void detach_CJ(CJ entity)
        {
            entity.XS = null;
        }
    }
}
